<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui'}){%>
    <style type="text/css">
        body{padding-top:10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>
<body>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <!-- START 右侧数据 -->
            <div class="ibox float-e-margins" style="margin-bottom: 0px;">
                <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                    <form id="search-form" role="form" class="form-inline">

                    </form>
                </div>
            </div>
            <!-- START 操作按钮 -->
            <form>
            <div id="toolbar" class="btn-group" style="margin-bottom:5px;">

                <input type="hidden" id="id" value="${id}">
                <a class="return-btn btn btn-sm btn-primary"><i class="fa fa-arrow-left" aria-hidden="true"></i> 返回</a>
<!--                <a class="export-btn btn btn-sm btn-success"><i class="fa fa-plus" aria-hidden="true"></i> 导出</a>-->
                <input type="hidden" id="materialId" name="materialId">
            </div>
            </form>
            <!-- END 操作按钮 -->

            <!-- START 数据表格 -->
            <table id="relatedTable"
                   data-toolbar="#toolbar"
                   data-side-pagination="server"
                   data-pagination="true"
                   data-resizable="true"
                   data-side-pagination="server"
                   data-url="/sea/operate/related/materialDetail/findByMaterialId.do?materialId=${id}"
                   data-page-size="15"
                   class="table table-striped table-hover table-responsive"
                   >
            </table>
            <!-- END 数据表格 -->

            <!-- END 右侧数据 -->
        </div>
    </div>
</div>

<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer,layui,upload'}){}%>
<script>

    var $relatedTable = $('#relatedTable'),selections=[];

    $(function(){
        //START 表格配置
        $relatedTable.bootstrapTable({
            pageSize:10,
            columns: [
                {
                    title: '辅料类型',
                    field: 'materialFL',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '下载附件',
                    field: 'materialShowFile',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if(null!=v && v!=''){
                            var result='<button class=" download-btn layui-btn  layui-btn-sm"  style="margin-top: -6px;margin-left: -4px">';
                            result+='<i class="fa fa-download" aria-hidden="true"></i> <a href="'+v+'" download style="color: white"  target="_blank" download>下载展示文件</a>';
                            result+='</button>';
                            return result;
                        }else{
                            return '';
                        }
                    }
                },
                {
                    title: '替换展示原文件',
                    field: 'materialShowFile',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if(null!=v && v!=''){
                            var result='<button data-val="'+r.id+'" name="import-show-btn" class="import-show-btn download-btn layui-btn  layui-btn-sm"  style="margin-top: -6px;margin-left: -4px">';
                            result+='<i class="fa fa-download" aria-hidden="true"></i> 替换展示文件';
                            result+='</button>';
                            return result;
                        }else{
                            return '';
                        }
                    }
                },
                {
                    field: 'operate',
                    title: '操作',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){
                $('.detail-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    layer.open({
                        type: 2,
                        area: ['700px','500px'],
                        content: ['/sea/supply/record/main.do?id='+id, 'yes']
                    });
                });

                $('.import-design-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    $("#materialId").val(id);
                });
                $('.import-show-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    $("#materialId").val(id);
                });


                layui.use('upload', function(){
                    var upload = layui.upload;
                    upload.render({
                        elem: '.import-design-btn', //绑定元素,
                        accept:'file',
                        url: '/sea/operate/related/materialDetail/importDesign/', //上传接口
                        data: {
                            materialId: function () {
                                return $("#materialId").val();
                            }
                        },
                        before:function () {

                            layer.load(1, {
                                shade: [0.1, '#fff'] //0.1透明度的白色背景
                            });
                        }
                        ,done: function(data){
                            if( data.ok ){
                                layer.msg("生成成功！",{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){ // 默认的是 按钮一

                                        layer.closeAll();
                                    }});
                                $relatedTable.bootstrapTable('refresh');
                            }else{
                                layer.msg(data.msg,{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){ // 默认的是 按钮一
                                        layer.closeAll();
                                    }});
                            }
                        }
                        ,error: function(){
                            //请求异常回调
                            layer.closeAll();
                        }
                    });
                });

                layui.use('upload', function(){
                    var upload = layui.upload;
                    upload.render({
                        elem: '.import-show-btn', //绑定元素,
                        accept:'file',
                        url: '/sea/operate/related/materialDetail/importShow/', //上传接口
                        data: {
                            materialId: function () {
                                return $("#materialId").val();
                            }
                        },
                        before:function () {

                            layer.load(1, {
                                shade: [0.1, '#fff'] //0.1透明度的白色背景
                            });
                        }
                        ,done: function(data){
                            if( data.ok ){
                                layer.msg("生成成功！",{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){ // 默认的是 按钮一

                                        layer.closeAll();
                                    }});
                                $relatedTable.bootstrapTable('refresh');
                            }else{
                                layer.msg(data.msg,{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){ // 默认的是 按钮一
                                        layer.closeAll();
                                    }});
                            }
                        }
                        ,error: function(){
                            //请求异常回调
                            layer.closeAll();
                        }
                    });
                });
            }
        });
        //END 表格配置
        //表格高度自适应
//        $(window).resize(function () {
//            $dealTable.bootstrapTable('resetView', {
//                height: getHeight()
//            });
//        });
    });


    $('.export-btn').on('click',function(){
        var id=$("#planId").val();
        window.location.href='/sea/supply/distribute/export.do?planId='+id;
    });

    //返回
    $('.return-btn').on('click',function(){
        parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭弹窗
    });


    layui.use('upload', function(){

        var upload = layui.upload;
        upload.render({
            elem: '.import-design-btn', //绑定元素,
            accept:'file',
            url: '/sea/operate/related/materialDetail/import/', //上传接口
            data:{materialId:1},
            before:function () {

                layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
            }
            ,done: function(data){
                if( data.ok ){
                    layer.msg("生成成功！"+data.data,{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){ // 默认的是 按钮一
                            layer.closeAll();
                        }});
                    $relatedTable.bootstrapTable('refresh');
                }else{
                    layer.msg(data.msg,{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){ // 默认的是 按钮一
                            layer.closeAll();
                        }});

                }
            }
            ,error: function(){
                //请求异常回调
                layer.closeAll();
            }
        });
    });
    function optFormatter(value,row){
        var content = '';
        content += '&nbsp;<button class="detail-btn btn btn-xs btn-default" data-val="'+row.id+'" title="查看记录"> 查看记录</button>';
        return content;
    }


</script>
</body>
</html>
